package dao

import (
	"gin-study/pkg/orm"
	"gorm.io/gorm"
)

var User = &user{}

type user struct {
	*gorm.DB
}

func init() {
	User = &user{
		DB: orm.DB(),
	}
}

func (u *user) ScopeKeywords(keywords string) Scope {
	return func(db *gorm.DB) *gorm.DB {
		if len(keywords) > 0 {
			db.Where("username = ?", keywords).Or("nickname= ?", keywords)
		}
		return db
	}
}
